<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
    <link>
</head>
<body>
<!--导航栏-->
<nav th:replace="admin/_fragments::menu(1)" class="ui  inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item ">后台管理</h2>
            <a class="active m-item item m-mobile-hide"><i class="home icon"></i>博客</a>
            <a class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <div class="right menu">
                <div class="ui dropdown m-item m-mobile-hide item">
                    <div class="text">
                        <img src="https://picsum.photos/id/1005/100/100" alt="" class="ui avatar image">
                        定春
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>
<!--二级导航-->
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" class="item" th:href="@{/admin/blogs/input}">发布</a>
            <a href="#" class="active teal item" th:href="@{/admin/blogs}">列表</a>
        </div>
    </div>
</div>


<!--中间部分-->
<div class="m-container m-padded-tb-big ">
    <div class="ui  container">
        <!--查询表单-->
        <div class="ui secondary segment form">
            <!--传给后台要第几页的分页参数-->
            <input type="hidden" name="page">
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}"
                                     th:text="${type.name}">错误日志
                                </div>
                                <!--/*-->
                                <div class="item" data-value="2">开发者手册</div>
                                <!--*/-->
                            </div>
                        </div>
                        <button id="clear-btn" class="ui compact button">clear</button>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field m-right ">
                    <button id="search-btn" class="ui mini teal  button"><i class="search icon"></i>搜索</button>
<!--                    <a class="ui mini teal button"><i class="add icon"></i>新增</a>-->
                </div>
            </div>
        </div>

        <!--博客表格-->
        <div id="table-container">
            <table th:fragment="blogList" class="ui celled compact teal table">
                <thead>
                <tr>
                    <th></th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>浏览量</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,iterStat : ${page.content}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">刻意练习清单</td>
                    <td th:text="${blog.type.name}">认知升级</td>
                    <td th:text="${blog.recommend} ? '是':'否'">是</td>
                    <td th:text="${blog.published} ? '公开':'私有'">草稿</td>
                    <td th:text="${#dates.format(blog.createTime,'yyyy-MM-dd HH:mm')}">2017-10-02 09:45</td>
                    <td th:text="${blog.views}">100</td>
                    <td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2017-10-02 09:45</td>
                    <td>
                        <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}"
                           class="ui mini teal basic button">编辑</a>
                        <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}"
                           class="ui mini red basic button">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <th colspan="9">
                        <!--th:if="${page.totalPages}>1" -->
                        <div class="ui mini pagination menu">
                            <!--h5自定义属性 data-* -->
                            <a onclick="page(this)" th:attr="data-page=${page.number}-1" class="item"
                               th:unless="${page.first}">上一页</a>
                            <span class="ui item ">
                                <a class="m-page-text" th:text="${page.number+1}">1</a>
                                <a>/</a>
                                <a th:text="${page.totalPages}">2</a>
                            </span>
                            <a onclick="page(this)" th:attr="data-page=${page.number}+1" class=" item"
                               th:unless="${page.last}">下一页</a>
                        </div>
                        <span class="ui  m-text-spaced">
                        &nbsp;  共<a th:text="${page.totalElements}"></a>篇博客
                        </span>
                        <a href="#" th:href="@{/admin/blogs/input}"
                           class="ui mini right floated teal basic button">新增</a>
                    </th>
                    <!--<th colspan="6">
                        <div class="ui right floated pagination menu">
                            <a class="icon item">
                                <i class="left chevron icon"></i>
                            </a>
                            <a class="item">1</a>
                            <a class="item">2</a>
                            <a class="item">3</a>
                            <a class="item">4</a>
                            <a class="icon item">
                                <i class="right chevron icon"></i>
                            </a>
                        </div>
                    </th>-->
                </tr>
                </tfoot>
            </table>

            <!--操作消息提示-->
            <div class="ui success message" th:unless="${#strings.isEmpty(msg)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${msg}">恭喜，操作成功！</p>
            </div>
        </div>


    </div>
</div>

<br>
<br>

<!--底部-->
<footer th:replace="_fragments::footer" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned  container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                <div class="ui inverted link list m-text-thin m-text-spaced m-opacity-mini">
                    <a href="#" class="item">用户故事 User story</a>
                    <a href="#" class="item">用户故事 User story</a>
                    <a href="#" class="item">用户故事 User story</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                <div class="ui inverted link list m-text-thin m-text-spaced m-opacity-mini">
                    <a href="#" class="item m-text-lined">Email: xingzq.dc@foxmail.com</a>
                    <a href="#" class="item">QQ: 1961329303</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">定春</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">
                    这是我的个人博客，也是我第一个上线的项目，我未来职业规划是当一名Java开发工程师，并朝着架构师的目标努力前行！</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2021 - 2022 Dingchun Designed by Dingchun</p>
    </div>
</footer>


<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<!--/*/</th:block>/*/-->

<script>
    $('#newblog-container').load(/*[[@{/footer/newblog}]]*/"/footer/newblog");
    /*隐藏导航栏右上角图标（PC端时）*/
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    /*弹出下拉框*/
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    //消息提示关闭初始化
    $('.message .close').on('click', function () {
        $(this).closest('.message').transition('fade');
    });

    //点击分页 将page.number-1的值赋给隐藏域input 并请求数据
    function page(obj) {
        $("[name='page']").val($(obj).data("page"));//data-page="${page.number}-1"
        loadData();
    }

    //ajax局部刷新 通过获取表单的组合条件(搜索参数) 来动态请求blogList数据
    function loadData() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
            title: $("[name='title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val()
        });
    }

    //搜索按钮点击
    $("#search-btn").click(function () {
        $("[name='page']").val(0);//默认当前第一页（page.number=0）
        loadData();
    });


    //清空分类
    $('#clear-btn').on('click', function () {
        $('.ui.type.dropdown')
            .dropdown('clear')
        ;
    });


</script>

</body>
</html>